package 数据结构系列;

public class 反转链表_206 {
    class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }

    public ListNode reverseList(ListNode head) {
        if (head == null || head.next == null) {
            return head;
        }
        ListNode last = reverseList(head.next);
        //让反转后的链表头节点指向它前面的那个节点
        head.next.next = head;//一般两个next连用：head.next代表节点.next代表指针。
        head.next = null;
        return last;
    }
}
